<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>代理商列表</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="/resource/layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="/resource/css/mylay.css">
		<link rel="stylesheet" href="./layui/layui/css/layui.css">
		<link rel="stylesheet" href="/resource/css/kpi_list.css">
		</link>
	</head>

	<body>
		<!-- 头部左侧工具栏 -->
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container layui-btn-group">
				<button type="button" class="layui-btn layui-btn-sm layui-btn-primary useradd_btn" lay-event="add">
					<i class="layui-icon">&#xe654;</i>
				</button>
				<!-- <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-event="creditAssess">信用评估</button> -->
			</div>
		</script>
		<div class="all">
			<!-- 表单元素 -->
			<div class="layui-tab">
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show geRenYeJi">
						<div style="padding: 20px; background-color: #F2F2F2;">
							<div class="layui-row layui-col-space15">
								<div class="layui-col-md12">
									<div class="layui-card" style="padding: 10px;">
										<form class="layui-form search">
											<div class="layui-form-item">
												<div class="layui-inline">
													<label class="layui-form-label">账号</label>
													<div class="layui-input-inline">
														<input class="layui-input" name="account" autocomplete="off">
													</div>
												</div>
												<div class="layui-form-mid" id="user">状态</div>
												<div class="layui-input-inline" style="width: 100px;">
													<select name="state" lay-verify="" id="selete">
														<option value="0">全部</option>
														<option value="1">正常</option>
														<option value="2">停用</option>
													</select>
												</div>

												<div class="layui-inline" style="text-align: center;">
													<button type="button" class="layui-btn" id="layui-btn1"
														data-type="search">搜索</button>
												</div>
											</div>
										</form>
									</div>
								</div>
							</div>
						</div>
						<table id="geRenYeJi" lay-filter="geRenYeJi"></table>

						<!-- 头部左侧工具栏 -->
						<script type="text/html" id="toolbarDemo">
							<div class="layui-btn-container layui-btn-group">
								<button type="button" class="layui-btn layui-btn-sm" lay-event="add">
									<i class="layui-icon">&#xe654;</i>
								</button>
							</div>
						</script>
						 <script type="text/html" id="switchState">
					        {{#if (d.state == 1) { }}
					         <span>正常</span>
					        {{# }else if(d.state == 2){ }}
					        <span>禁用</span>
					        {{# } }}
					    </script>
					     <script type="text/html" id="switchDate">
					     {{layui.util.toDateString(Number(d.reg_time+'000'))}}

					    </script>

					     <!--//{{layui.util.toDateString(new Date('d.reg_time').getTime(), "yyyy-MM-dd HH:mm:ss")}}-->
					</div>

				</div>
			</div>
		</div>
		<script type="text/html" id="action">
			<div class="layui-btn-group">
				<button type="button" class="layui-btn layui-btn-xs" lay-event="agentDetail">详情</button>
				<button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
			</div>
		</script>
		<script src="/resource/layuiadmin/layui/layui.js"></script>
		<script src="/resource/js/manage/init_date.js"></script>
		<script src="/manage/user.js"></script>
		<script src="./layui/layui/layui.js"></script>
		<style>
			.layui-table-cell{
				height:56px;
			}
		</style>
		<script>
			//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
			layui.use(['element', 'table', 'form'], function() {
				var form = layui.form;
				var element = layui.element;
				var $ = layui.$;
				var table = layui.table;
				var laydate = layui.laydate;
				laydate.render({
					elem: '#datetimeRange',
					type: 'datetime',
					range: true
				});
				// 头部左侧工具栏事件
				table.on('toolbar(geRenYeJi)', function(obj) {
					switch (obj.event) {
						case 'add':
							layer.open({
								type: 2,
								area: ['550px', '440px'],
								title: '添加代理商',
								content: '/manage/Useragent/agentAdd'
							});
							break;
					};
				});
				//-----------------------个人
				table.render({
					elem: '#geRenYeJi',
					title: "代理奖励查询列表",
					skin: 'line',
					even:false,
					url: '/manage/useragent/agentList',
					method: 'get',
					cols: [
						[
							//表头
							{
								field: 'id',
								title: 'ID', fixed: 'left', width: 120
							},{
								field: 'username',
								title: '账号', width: 620
							},
							{title: '操作', width: '20%', toolbar: '#action'}
						]
					],
					cellMinWidth: 50,
					toolbar: '#toolbarDemo',
					defaultToobar: [],
					totalRow: true,
					page: {
						layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
					},

				});
				// 监听工具条
				table.on('tool(geRenYeJi)', function(obj){
					switch (obj.event) {
						case 'edit':
							layer.open({
								type: 2,
								area: ['80%', '80%'],
								title: '编辑代理',
								content: '/manage/useragent/edit?id='+obj.data.id
							});
							break;

						case 'agentDetail':
							layer.open({
								type: 2,
								area: ['90%', '90%'],
								title: '代理详情 - ID：'+obj.data.id,
<<<<<<< HEAD
								content: '/manage/useragent/agentDetail?id='+obj.data.id
=======
								content: '/manage/Useragent/agentDetail?uid='+obj.data.id
>>>>>>> d5744068e96ec6af195a083b33e0e08e138eee33
							});
							break;

						case 'del':
							layer.confirm('确认删除该代理？', {
								btn: ['确定','取消'] //按钮
							}, function(){
								$.ajax({
									url: "/manage/useragent/agentDel",
									data: {
										id: obj.data.id
									},
									type: "POST",
									dataType: "json",
									beforeSend: function(){
										layer.load(1);
									},
									success: function(msg){
										debugger
										var alertStr = (msg == 1) ? '操作成功' : msg;
										layer.msg(alertStr, {time: 2000}, function(){
											if(msg==1){
												layer.closeAll();
												layui.table.reload('geRenYeJi');
											}
										});
									},
									complete: function(){
										layer.closeAll("loading");
									}
								});
							}, function(){
								layer.msg('取消操作', {
									time: 2000, //2s后自动关闭
								});
							});
							break;
					}
				});
				active1 = {
					search: function() {
						console.log('搜索')
						//执行重载
						table.reload('geRenYeJi', {
							page: {
								curr: 1 //重新从第 1 页开始
							},
							where: {
								username: $("input[name='username']").val(),
								account: $("input[name='account']").val(),
								state: $("select[name='state'] option:selected").val(),
								datetimeRange: $("input[name='datetimeRange']").val(),
							}
						}, 'data');
					}
				};

				$('.geRenYeJi #layui-btn1').on('click', function() {
					var type = $(this).data('type');
					active1[type] ? active1[type].call(this) : '';
				});
			});
		</script>
	</body>
</html>
